package cn.com.egova.demoapplication.base;

import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.view.MenuItem;

public abstract class BaseActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setBackIconVisible(isBackIconVisible());
        initData();
    }


    /**
     * 设置是否在菜单栏显示返回按钮图标.
     * @param isVisible
     */
    public void setBackIconVisible(boolean isVisible){
        ActionBar actionBar = getActionBar();
        if(null != actionBar) {
            actionBar.setDisplayHomeAsUpEnabled(isVisible);
            actionBar.setDisplayShowHomeEnabled(false); //默认不显示应用程序图标.
        }
    }

    /**
     * 控制返回图标是否可见的标记.
     * @return
     */
    public boolean isBackIconVisible() {
        return false;
    }

    public void initData(){
        String title = getIntent().getStringExtra("title");
        setTitle(title);
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
